package com.neu.controller;

import com.neu.pojo.CheckOut;
import com.neu.service.CheckOutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
public class CheckOutController {
    @Autowired
    private CheckOutService checkOutService;

    /**
     * 获取全部退房信息
     */
    @RequestMapping("getCheckOutList")
    @ResponseBody
    public HashMap getCheckOutList(){
        List<CheckOut> list= checkOutService.getCheckOutList();
        HashMap<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("list",list);
        return map;
    }

    /**
     * 根据入住号删除退房信息
     */
    @RequestMapping("delCheckOut")
    @ResponseBody
    public HashMap delCheckOut(int checkInNum){
        int res=checkOutService.delCheckOut(checkInNum);
        HashMap<String,Object> map=new HashMap<>();
        if(res>0){
            map.put("code",0);
            map.put("msg","删除成功");
        }
        else {
            map.put("code",-1);
            map.put("msg","删除失败");
        }
        return map;
    }

    /**
     * 根据入住号修改退房信息
     */
    @RequestMapping("updateCheckOut")
    @ResponseBody
    public HashMap updateCheckOut(CheckOut checkOut){
        int res=checkOutService.updateCheckOut(checkOut);
        HashMap<String,Object> map=new HashMap<>();
        if(res>0){
            map.put("code",0);
            map.put("msg","修改成功");
        }
        else {
            map.put("code",-1);
            map.put("msg","修改失败");
        }
        return map;
    }

    /**
     * 根据新增退房信息
     */
    @RequestMapping("addCheckOut")
    @ResponseBody
    public HashMap addCheckOut(CheckOut checkOut){
        int res=checkOutService.addCheckOut(checkOut);
        HashMap<String,Object> map=new HashMap<>();
        if(res>0){
            map.put("code",0);
            map.put("msg","新增成功");
            map.put("data",checkOut);
        }
        else {
            map.put("code",-1);
            map.put("msg","新增失败");
        }
        return map;
    }

    @RequestMapping("getCheckOutByPage")
    @ResponseBody
    public HashMap getCheckOutByPage(int page, int limit){
        List<CheckOut> list=checkOutService.getCheckOutByPage(page,limit);
        int totalCount=checkOutService.getCheckOutCount();
        HashMap<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("msg","success");
        map.put("count",totalCount);
        map.put("data",list);
        return map;
    }

}
